Namespace Keyboard

    Module mKeyboard

        Private Structure KeyboardEvent
            Dim type As KeyboardInputType
            Dim e As Object
        End Structure

        Dim keybuffer As New Queue(Of KeyboardEvent)

        Public Sub Input(ByRef type As KeyboardInputType, ByRef e As System.Windows.Forms.KeyEventArgs)

            SyncLock keybuffer

                Dim tmp As KeyboardEvent
                tmp.type = type
                tmp.e = e
                keybuffer.Enqueue(tmp)

            End SyncLock

        End Sub

        Public Sub Input(ByRef type As KeyboardInputType, ByRef e As KeyPressEventArgs)

            SyncLock keybuffer

                Dim tmp As KeyboardEvent
                tmp.type = type
                tmp.e = e
                keybuffer.Enqueue(tmp)

            End SyncLock

        End Sub

        Public Sub DoInputs()

            Try

                SyncLock keybuffer

                    Dim msg As KeyboardEvent

                    Do Until keybuffer.Count = 0

                        msg = keybuffer.Dequeue()
                        Windows.KeyboardInput(msg.type, msg.e)

                    Loop

                End SyncLock

            Catch ex As Exception

            End Try

        End Sub


    End Module

End Namespace
